<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { statisticsApi } from '@/api/controller';
  import { Toastloading } from '@/utils/public';
  import { getPlayEndTime, getDateArray } from '@/utils'
  import serachUserid from '@/components/serachUserid/index.vue'
  import Pagination from "@/components/Pagination/index.vue";
  const action = reactive({
    list:[] as any[],
    total:0,
    dateArr:getDateArray('ymdhis') as Array<number>
  })
  const listQuery = reactive({
    openid:'',
    money:'',
    page:1,
    limit:20,
  })
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      openid:'',
      money:'',
      page:1,
      limit:20,
    })
    action.dateArr = getDateArray('ymdhis') as Array<number>
    getList()
  }
  const handleSerach = ()=>{
    listQuery.page = 1
    getList()
  }
  const getList = async()=> {
    const loading = Toastloading()
    const timeObj = getPlayEndTime(action.dateArr)
    const res = await statisticsApi.getJmRewardList({
      ...listQuery,
      timeSt:timeObj.playTime,
      timeEd:timeObj.endTime
    })
    loading.close()
    const { data=[], total=0 } = res.data || {}
    action.list = data
    action.total = total
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">openid：</div>
          <el-input clearable v-model="listQuery.openid" placeholder="用户opened" />
        </div>
        <div class="labelItem">
          <div class="label">金额单位(分)：</div>
          <el-input clearable v-model="listQuery.money" placeholder="金额单位(分)" />
        </div>
        <div class="labelItem">
          <div class="label">日期：</div>
          <el-date-picker
            v-model="action.dateArr"
            type="datetimerange"
            format="YYYY-MM-DD HH:mm:ss "
            value-format="YYYY-MM-DD HH:mm:ss"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column min-width="120" prop="id" label="序号" />
      <el-table-column min-width="120" prop="qr_str" label="二维码字符串" />
      <el-table-column min-width="120" sortable prop="r_status" label="状态">
        <template #default="scope">
          {{ ['未打款','已打款'][scope.row.r_status] }}
        </template>
      </el-table-column>
      <el-table-column min-width="120" sortable prop="pool_id" label="礼物池序号" />
      <el-table-column min-width="120" sortable prop="money" label="领取到的金额(分)" />
      <el-table-column min-width="120" sortable prop="openid" label="用户openid" />
      <el-table-column min-width="120" sortable prop="nickname" label="用户nickname" />
      <el-table-column min-width="120" sortable prop="headimgurl" label="用户headimgurl" />
      <el-table-column min-width="120" sortable prop="d_time" label="中奖时间" />
      <el-table-column min-width="120" sortable prop="m_time" label="发钱时间" />
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
  </div>
</template>
